<?php

namespace Keio\StudyBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Keio\StudyBundle\Entity\Blog;
use Keio\StudyBundle\Entity\Blogcomment;

class BlogcommentController extends Controller
{

    public function createAction(Request $request, $blog_id)
    {
    	$em = $this->getDoctrine()->getManager();
    	$blog = $em->getRepository('KeioStudyBundle:Blog')->find($blog_id);

        $request = $this->getRequest();
		$data_form_name = $request->request->get('name');
		$data_form_email = $request->request->get('email');
		$data_form_comment = $request->request->get('comment');

		$comment = new Blogcomment();
		$comment->setAuthor($data_form_name);
		$comment->setEmail($data_form_email);
		$comment->setComment($data_form_comment);
		$comment->setBlog($blog);
		$comment->setDatecreate(new \DateTime());


        $em->persist($comment);
        $em->flush();

        //return $this->redirect($this->generateUrl('blog'));
        return $this->redirect($this->generateUrl('blog_show', array('id' => $blog_id)));
    }
}
